<template>
  <div class="view-container">
    <table-search-view :table-items="tableItems" :search-items="searchItems" :search-function="getTableDate">
      <template slot="orderId" slot-scope="scope">
        <el-button type="text" @click.stop.prevent="orderDetail(scope.row.orderNumber)">{{scope.row.orderNumber}}</el-button>
      </template>
    </table-search-view>
  </div>
</template>

<script>
  import TableSearchView from '@/components/TableSearchView';
  import {getTradingType, getTradingRecords} from '@/api/assets';

  export default {
    name: 'assetsTrading', //交易流水
    components: {
      'table-search-view': TableSearchView,
    },
    data()
    {
      return {
        searchItems: [
          {
            label: '交易类型',
            type: 'select',
            placeholder:'请选择交易类型',
            model:'transactionType',
            clearable:true,
            multiple:true,
            filterable:true,
            options:[
              {
                label:'收入－租金',
                value:'in_rent',
              },
              {
                label:'收入－买断金',
                value:'in_broken_gold',
              },
              {
                label:'收入－收取押金',
                value:'in_cash_pledge',
              },
              {
                label:'收入－赔偿金',
                value:'in_damage',
              },
              {
                label:'收入－逾期违约金',
                value:'in_overdue_liquidated_damages',
              },
              {
                label:'收入－首期租金',
                value:'in_first_period_rent',
              },
              {
                label:'收入-撤回提现',
                value:'in_withdraw_recall',
              },
              {
                label:'支出－退还押金',
                value:'ex_refund',
              },
              {
                label:'支出－提现',
                value:'ex_withdraw',
              },
            ]
          },
          {
            label: '交易时间',
            type: 'datetimerange',
            placeholder:'请选择交易时间',
            model:'timeRange',
          },
          {
            label: '关联订单',
            type: 'input',
            placeholder:'请输入关联订单',
            model:'billNumber',
          },
        ],
        tableItems:[
          {
            label:'关联订单',
            prop:'orderNumber',
            width:'190px;',
            sortable:true,
            type:'scope',
            slot:'orderId',
          },
          {
            label:'账期编号',
            prop:'billNumber',
            width:'190px;',
          },
          {
            label:'交易类型',
            prop:'transactionTypeStr',
            width:'240px;',
            sortable:true,
          },
          {
            label:'交易金额',
            prop:'transactionMoney',
            sortable:true,
            width:'160px;',
            formatter:'parsePrice',
          },
          {
            label:'余额',
            prop:'balance',
            width:'160px;',
            formatter:'parsePrice',
          },
          {
            label:'冻结金额',
            prop:'frozen',
            width:'160px;',
            formatter:'parsePrice',
          },
          {
            label:'交易时间',
            prop:'transactionTime',
            width:'180px;',
            formatter:'parseTime',
          },
          {

          }
        ],
      }
    },
    mounted()
    {
      //获取交易类型
      getTradingType().then(resp=>{
        let data = resp.data || {};
        let options = [];
        //console.log(data);
        for(let key in data)
        {
          options.push({label:data[key],value:key});
        }

        this.searchItems[0].options = options;
      }).catch(err=>{

      });
    },
    methods: {
      getTableDate(data) //获取数据
      {
        return getTradingRecords(data);
      },
      orderDetail(id)
      {
        this.$router.push({name:'orderInfo',query:{id:id}})
      }
    }
  }
</script>

<style lang="less" scoped>

</style>

